package com.jianying.day03;

import com.jianying.beans.WaterSensor;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * ClassName: Flink09_Trans_Map
 * Package: com.atguigu.day03
 * Description:
 *
 * @Author: tubage
 * @Create: 2024/4/1 15:05
 * @Version: 1.0
 */
public class Flink09_Trans_Map {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<WaterSensor> waterSensorDS = env.fromElements(new WaterSensor("ws1", 10L, 10), new WaterSensor("ws1", 10L, 10));

        SingleOutputStreamOperator<String> idDs = waterSensorDS.map(
                new MapFunction<WaterSensor, String>() {
                    @Override
                    public String map(WaterSensor waterSensor) throws Exception {
                        return waterSensor.id;
                    }
                }
        );
        // lambda
        // 方法引用
        // 单独封装类实现
        idDs.print();

        env.execute();
    }
}
